package com.more.offer.threadtest.joinTest;

/**
 * @author pinoc
 * @date 2021/6/20
 * @description 测试线程的join 方法
 */
public class JoinInterruptTest {
	public static void main(String[] args) {

		final Thread mainThread = Thread.currentThread();
		Thread one = new Thread(new Runnable() {
			@Override
			public void run() {
				System.out.println("thread one running");
				for (;;) {
				}
			}
		});

		Thread two = new Thread(new Runnable() {
			@Override
			public void run() {
				System.out.println("thread two running");
				try {
					Thread.sleep(2000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				mainThread.interrupt();
			}
		});

		one.start();
		two.start();
		try {
			one.join();
		} catch (InterruptedException e) {
			System.out.println("main thread: " + e);
		}
	}
}
